<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>商品详情</title>
<link rel="stylesheet" type="text/css" href="/style/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/swiper.min.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/xshop.css?ver=2019041401"/>
<link rel="stylesheet" type="text/css" href="/style/css/sweet-alert.css"/>	
<style type="text/css">
.share{
    float: right;
    text-align: center;
    color: #2c2c2c;
    font-size: .25rem;
    line-height: .5rem;
    margin-right: .3rem;
}
.foot-goodsdetail-left a{    width: 50%;
    display: flex;
    justify-content: center;
    float: left;}	
</style>
<script src="/style/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/xShop.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/sweet-alert.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/style/new/js/jquery.lazyload.js"></script>
<script type="text/javascript" src="/style/wei/js/jquery.cookies.js"></script>
</head>
<body>
<!--banner-->
<div class="topBanner topBannerpt topBannerspi">

	<?php
	if($this->data['stock_number'] <1)
	{
		echo '<div class="nostock">补货中</div>';
	}
	?>			
	<div class="swiper-wrapper">
	
    	<?php
    	$default_share = '';
    	$cnt = count($this->data['docids']);
		if($this->data['docids'] && $this->data['docs']){
			foreach($this->data['docids'] as $r){

				if($default_share == "")
				{
					$default_share = $this->data['docs'][$r];
				}
		?>
			<div class="swiper-slide"><a href="#"><img src="<?=$this->data['docs'][$r];?>" /></a></div>
		<?
			}
		}
		?>        
	</div>
	
	<div class="swiper-pagination"></div>
</div>

		</div>
<div class="spi-top-info">
	<div class="info">

		<div class="tit clearfix"><h2><?=$this->data['goods_name'];?></h2>
		</div>
		
		<div class="preicebar price">

			<span class="price"><b><?php
			if($this->data['shop_price']>0)
			{
				echo '￥'.$this->data['shop_price'];
			}
			elseif($this->data['ximi_price'])
			{
				echo ($this->data['ximi_price']*1).'硒米';
			}
			?></b></b></span>
			<?php
			// 市场价格
			if($this->data['market_price']>0)
			{
				echo '<del>￥'.$this->data['market_price'].'</del>';
			}
			// 分享
			/* if($this->app ==1)
			{
			    echo '<div class="share" onClick="_share();"><p></p>分享 </div>';
			} */
			// 收藏
			if($this->data['collection']>0)
			{
				echo '<div class="collection curr"><p></p>已收藏</div>';
			}
			else
			{
				echo '<div class="collection"><p></p>收藏</div>';
			}
			?>

			<div class="more">
			<?

			// 折扣与省多少元

			
						
			if($this->data['price_me']>0){	
				echo '<div class="zhekou">返'.($this->data['price_me'] * 1).'</div>';
			}
			if($this->data['coupon_price'] > 0)
			{
				echo '<div class="sheng">抵券'.$this->data['coupon_price'].'</div>';
			}	
				
			

			if($this->data['goods_jifen']>0){	
				echo '<div class="zhekou">积分'.($this->data['goods_jifen']*1).'</div>';
			}


			// 仓库类型
			if($this->data['warehouse_type'] == 1)
			{
				//echo '<div class="warehouse bendi"><u>&nbsp;</u><i>本地仓</i></div>';
			}
			elseif($this->data['warehouse_type'] == 2)
			{
				echo '<div class="warehouse baoshui"><u>&nbsp;</u><i>保税仓</i></div>';
			}
			elseif($this->data['warehouse_type'] == 3)
			{
				echo '<div class="warehouse haiwai"><u>&nbsp;</u><i>海外仓</i></div>';
			}


			if($this->data['price_level1']>0 && $this->member_level>=1)
			{
				echo '<div class="share">推广赚'.($this->data['price_level1'] * 1).'</div>';
			}

			?>

			
			</div>
		  	
		</div>
		<?php
		if($this->reles['goods']){ 

			if( $this->reles['option_name'] == "")
			{
				$this->reles['option_name'] = '选择';
			}

			echo '<div class="tit preicebar relevance"><div class="option">'.$this->reles['option_name'].'</div><div class="items">';

		    foreach($this->reles['goods'] as $key=>$val){

		    	if($val['rele_title']=="")
		    	{
		    		$val['rele_title'] = $val['goods_name'];
		    	}

		    	if($val['goods_id'] == $this->data['goods_id'])
		    	{
		    		$curr = ' class="curr"';
		    	}
		    	else
		    	{
		    		$curr = '';
		    	}

		    	echo '<a'.$curr.' href="/index/goodsdetail?goods_id='.$val['goods_id'].'">'.$val['rele_title'].'</a>';

			}
			echo '</div></div>';
		}
		?>
		<div class="tt clearfix">			            
            <span class="time-t">已销<?=$this->data['sales_count'];?>笔</span>
            <span class="num-t">&nbsp;</span>
            <span class="didian">库存<?=$this->data['stock_number'];?>件</span>
		</div>

	</div>
</div>

 

<div class="spi-bz clearfix">
	<!-- <span>
		<i class="ico"><img src="/style/new/images/me/open_2.png"/></i>
		<h2>全场折扣</h2>
	</span>
	<span>
		<i class="ico"><img src="/style/new/images/me/open_1.png"/></i>
		<h2>买贵就赔</h2>
	</span>
	<span>
		<i class="ico"><img src="/style/new/images/me/open_6.png"/></i>
		<h2>会员免邮</h2>
	</span>
	<span>
		<i class="ico"><img src="/style/new/images/me/open_4.png"/></i>
		<h2>无忧退换</h2>
	</span>
	<span>
		<i class="ico"><img src="/style/new/images/me/open_3.png"/></i>
		<h2>闪电退款</h2>
	</span> -->
</div>



<div class="pt-dtl">
	<div class="cont">
		<?php 
		$desc = htmlspecialchars_decode($this->data['goods_desc']);
		$desc = str_replace("<img src=","<img class=\"lazyimg\" src=\"/style/images/lazycover.jpg\" data-original=",$desc);
		  echo $desc;
		?>		
	</div>
</div>
	
<!--底部导航-->
<div class="foot-pt foot-spi clearfix">
	<div class="ct">
		<div class="foot-goodsdetail-left">		
			<a href="/"><div><img src="/style/new/images/icon_home.png" /><br>首页</div></a>
			<a href="/cart/cart"><div id="cartStatus"><?php if($this->cartnum >0 ) echo '<span class="cartnum">'.$this->cartnum.'</span>';?><img src="/style/new/images/icon_cart.png" /><br>购物车</div></a>		
		</div>		
	    <a href="javascript:_addtocart(<?php echo $this->data['goods_id']?>,1);" class="bn-go btn-dd nowgm"><p>立即购买</p></a>
		<a href="javascript:_addtocart(<?php echo $this->data['goods_id']?>,0);" class="bn-go btn-kt"><p>加入购物车</p></a>
	</div>
</div>

<div class="popdetail">
	<span class="price"><b><?php
	if($this->data['shop_price']>0)
	{
		echo '￥'.$this->data['shop_price'];
	}
	elseif($this->data['ximi_price'])
	{
		echo ($this->data['ximi_price']*1).'硒米';
	}
	?></b></span> 
	
	<?php
	
	if($this->data['coupon_price'] > 0)
	{
		echo '<div class="sheng">抵券'.$this->data['coupon_price'].'</div>';
	}
	if($this->data['price_me']>0){	
		echo '<div class="zhekou">返'.($this->data['price_me']*1).'</div>';
	}	
	?>
	
</div>
<!-- <div class="hongbao-fixd none">
	<a href="javascript:_gotoTop();"><img src="/style/wei/images/home/fb2.png"/></a>
</div> -->
<script type="text/javascript">
var _added = false,
_goodsid=<?=$this->data['goods_id']?>,
_goods_number = <?=$this->data['stock_number'];?>,
_g_top = 0;
_cnt = <?=$cnt;?>;


$(document).ready(function() {

	if(_goods_number < 1)
	{
		$(".foot-pt .bn-go").addClass("disabled");
	}
	
	$(".lazyimg").lazyload({
      threshold : 150,
      placeholder : "/style/images/lazycover.jpg",
      failurelimit : 4
    });
	
	$(".cont img").removeAttr("height").removeAttr("width").css({"width":"100%","height":"auto"});

	// 收藏
	$(".spi-top-info .preicebar .collection").on("click",function(){

		$.post("/index/ajax",
		{
			"act":"collection",
			"goods_id":_goodsid,
			"mr":Math.random()
		},function(json){
			console.log(json);
			if(json.code==200)
			{
				if(json.result ==1)
				{
					$(".spi-top-info .preicebar .collection").html('<p></p>已收藏').addClass("curr");
				}
				else
				{
					$(".spi-top-info .preicebar .collection").html('<p></p>收藏').removeClass("curr");
				}
			}
		},"json");

	});	


    $(document).on("scroll",function(){

    	var _line = $(".pt-dtl").position().top;
    	if($(document).scrollTop() > $(".pt-dtl").position().top - 100)
    	{
    		if(_g_top == 0)
    		{
    			$(".popdetail,.hongbao-fixd").fadeIn();
    			_g_top = 1;
    		}
    	}
    	else
    	{
    		if(_g_top == 1)
    		{
    			$(".popdetail,.hongbao-fixd").fadeOut();
    			_g_top = 0;
    		}
    		
    	}

    });


    if(_cnt>1)
    {
    	var swiper = new Swiper('.topBanner', {
		    // 如果需要分页器
		    pagination: '.swiper-pagination',
		    
			// 如果需要前进后退按钮
		    nextButton: '.swiper-button-next',
		    prevButton: '.swiper-button-prev',
		    
		    // paginationClickable: '.swiper-pagination',  // paginationClickable: '.swiper-pagination'是控制到最底或最早，不能从最后一个到第一个这样循环

		    slidesPerView: 1,
		    paginationClickable: true, //paginationClickable: true,可以实现从最后一个到第一个这样循环
		    spaceBetween: 30,
		    	loop: true,
		    	autoplay: 2000,
		    	autoplayDisableOnInteraction: false
		});
    }

    
});

function _gotoTop()
{
	$(document).scrollTop(0);
}


function _addtocart(goods_id,goto){
	if(_goods_number > 0){
		$.post("/cart/cart_ajax",
			{
				"goods_id":goods_id,
				"goods_number":1,
				"mr":Math.random()
			},
			function(json){					
				if(json.code == 200) {				
					_added = true;
                    if (goto == 1)
                    {
                    	window.location.href = '/cart/cart';
                    }
                    else
                    {
                    	swal('添加到购物车成功', false, "success");
                    	if(json.cartnum>0)
                    	{
                    		if( $("#cartStatus span").hasClass("cartnum"))
                    		{
                    			$("#cartStatus span").html(json.cartnum);
                    		}
                    		else
                    		{
                    			$("#cartStatus img").before('<span class="cartnum">'+json.cartnum+'</span>')
                    		}
                    	}
                    }
				}
				else if(json.code==780) swal("商品补货中");
				else if(json.code==781) swal("商品补货中");
				else if(json.code==782) swal("已超过限购数量");
				else if(json.code==783) swal("商品补货中");
				else if(json.code==800) window.location.href = '/passport/signin';
				else swal("加入购物车失败，请重试"+msg);
				
		},"json");
	}	
}
</script>

<?php
if($this->JSAPI){

	if($default_share == "")
	{
		$default_share = 'http://'.$_SERVER['HTTP_HOST'].'/style/wei/images/tuijian/tj_logo_big2.jpg';
	}
?>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
wx.config({
  appId: '<?=$this->JSAPI['appId'];?>',
  timestamp: '<?=$this->JSAPI['timestamp'];?>',
  nonceStr: '<?=$this->JSAPI['nonceStr'];?>',
  signature: '<?=$this->JSAPI['signature'];?>',
  jsApiList: [
    'onMenuShareTimeline',
    'onMenuShareAppMessage'
  ]
});
wx.checkJsApi({
    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'],
    success: function(res) {
    }
});
wx.ready(function () {
  wx.onMenuShareAppMessage({
    title: '<?=$this->data['goods_name'];?> - 西海良品',
    desc: '绿色富硒、好吃不贵的优质农产品，自购省钱、分享返钱，欢迎加盟...',
    link: '<?=$this->JSAPI['url'];?>',
    imgUrl: '<?=$default_share;?>',
    type: 'link',
    dataUrl: '',
    success: function () {   
    },
    cancel: function () {
    }
  });
  
    // 分享到朋友圈
    wx.onMenuShareTimeline({
      title: '<?=$this->data['goods_name'];?> - 西海良品',
      link: '<?=$this->JSAPI['url'];?>',
      imgUrl: '<?=$default_share;?>',
      success: function () {
    },
    cancel: function () {
    }
  });  

});
</script>
<?
}
?>
</body>
</html>